#ifndef __AS_BUTTON__H__
#define __AS_BUTTON__H__

#include "ASControl.h"
#include "ASLabel.h"
#include "ASImage.h"

#define AS_BUTTON_SUPPORT_KEYCODE_MAX 4

typedef ASVOID (*as_button_cb)(ASVOID);

typedef enum
{
    AS_TEXT_BUTTON,
    AS_IMAGE_BUTTON,

    AS_BUTTON_TYPE_MAX
} as_button_type;

typedef enum
{
    AS_BUTTON_UP,
    AS_BUTTON_DOWN,
    AS_BUTTON_DISABLE,

    AS_BUTTON_STATUS_MAX
} as_button_status;

typedef union
{
    as_label* label;
    as_image* images[AS_BUTTON_STATUS_MAX];
} as_button_element;

typedef struct
{
    /* base */
    as_control base;

    /* attributes */
    as_button_type type;
    as_button_status status;
    as_button_element elem;
    ASINT key_code_list[AS_BUTTON_SUPPORT_KEYCODE_MAX];//internal used : store key codes binding to this button
    ASINT if_selected_by_down_event;//internal used : if this button selected by pen down or key down
    as_button_cb cb[AS_BUTTON_STATUS_MAX];//internal used
    ASUINT bg_color;
    /* methods */

    /*
     *	[description] change button status
     *  [param] ctrl_p : which one to deal pen
     *  [param] status : enum of as_button_status
     *  [return] as_ret : AS_OK or error code
     */
    as_ret (*change_status)(as_control* ctrl_p, as_button_status status);

    /*
     *	[description] reset button status,reset to up status
     *  [param] ctrl_p : which one to deal pen
     *  [return] as_ret : AS_OK or error code
     */
    as_ret (*reset_status)(as_control* ctrl_p);

    /*
     *	[description] add key to tie on this button
     *  [param] ctrl_p : which one to deal key
     *  [param] key_code : which key
     *  [return] as_ret : AS_OK or error code
     */
    as_ret (*add_keycode)(as_control* ctrl_p, ASINT key_code);

    /*
     *	[description] delete key from key_list tied on this button
     *  [param] ctrl_p : which button to deal key
     *  [param] key_code : which key
     *  [return] as_ret : AS_OK or error code
     */
    as_ret (*delete_keycode)(as_control* ctrl_p, ASINT key_code);

    /*
     *	[description] set callback to button status(as_button_status)
     *  [param] ctrl_p : which button to add callback
     *  [param] status : enum of as_button_status
     *  [param] p : callback function
     *  [return] as_ret : AS_OK or error code
     */
    as_ret (*set_cb_by_status)(as_control* ctrl_p, as_button_status status, as_button_cb p);

    /*
     *	[description] reset callback function
     *  [param] ctrl_p : which button to delete callback function
     *  [param] status : enum of as_button_status
     *  [param] p : callback function
     *  [return] as_ret : AS_OK or error code
     */
    as_ret (*reset_cb_by_status)(as_control* ctrl_p, as_button_status status);

    /*
     *	[description] just for image button,you can set offset of images in button area.
     *  [param] ctrl_p : which button
     *  [param] x_off : axis of x, relative to button area
     *  [param] y_off : axis of y, relative to button area
     *  [return] as_ret : AS_OK or error code
     */
    as_ret (*set_show_offset)(as_control* ctrl_p, ASINT x_off, ASINT y_off);

    /*
     *	[description] just for text button,you can set bg color of text button.
     *  [param] ctrl_p : which button
     *  [param] color : color of bg
     *  [return] as_ret : AS_OK or error code
     */
    as_ret (*set_bg_color)(as_control* ctrl_p, ASUINT color);

    as_ret (*set_image_btn_trans)(as_control* ctrl_p, ASINT if_trans);
} as_button;

/*
 *	[description] create a button control
 *  [param] area : area of this control
 *  [param] type : as_button_type
 *  [param] param1 : if text button,it is text;if image button,it is up_img path
 *  [param] param2 : if text button,it is NULL;if image button,it is down_img path
 *  [param] param3 : if text button,it is NULL;if image button,it is disable_img path
 *  [param] img_src_type : if text button,it is NULL;if image button,it is image source type
 *  [return] as_button* : if NULL , means create failed.
 *                       else return the pointer of label.
 */
as_button* as_ctrl_button_create(as_rect area, as_button_type type,
                                 ASWSTR param1, ASWSTR param2, ASWSTR param3, ASUINT img_src_type);
//as_button* as_ctrl_text_button_create(ASUINT8* paint_buf, as_rect area, ASWSTR text);
//as_button* as_ctrl_image_button_create(ASUINT8* paint_buf, as_rect area, ASWSTR up_img,ASWSTR down_img,VMSTR disable_img);
/*
 *	[description] destroy a existed label
 *  [param] ctrl_button_p : pointer of button control
 *  [return] as_ret : AS_OK means destroy successful,else are abnormal.
 */
as_ret as_ctrl_button_destroy(as_button* ctrl_button_p);

#endif//__AS_BUTTON__H__